export class Base {
	ctx;
	imageStatus;
	constructor(ctx) {
		if (!ctx || (ctx.toString() !== "[object CanvasRenderingContext2D]")) throw Error("you should provide a canvas2d context")
		this.ctx = ctx
	}
	getPxImageData({x, y, width = 1, height = 1} = { x: 0, y: 0, width: 1, height: 1 }) {
		return this.ctx.getImageData(x, y, width, height)
	}
	getFrameImageData() {
		let {
			width,
			height
		} = this.ctx.canvas
		return this.ctx.getImageData(0, 0, width, height)
	}
	download(filename) {
		this.imageStatus.then(() => {
			let img = this.ctx.canvas.toDataURL()
			let link = document.createElement('a')
			link.href = img
			link.download = filename + '.png'
			link.click()
		}).catch(e => {
		})
	}
}